<?php 
include 'conf/configuracion_idioma.php';
include 'conf/common_index.php';
include 'template_include_index.php';
?>

<?php 
if(logged_in()){
	$url = "http://".DOMINIO_BASE_COMPLETO;
	exit('<meta http-equiv="refresh" content="0; url=' . urldecode($url) . '"/>');
}
?>

<?php $title = gettext("Iniciar Sesion | Anuncios Locales")?>
<?php $descripcion = gettext("Iniciar Sesion | Anuncios Locales")?>
<?php $keywords = gettext("Iniciar Sesion | Anuncios Locales")?>

<?php include 'template_header_index.php'?>

<?php include 'template_nav_bar_index.php';?>

<?php 
   $login_erros = array();
   $url_from = getenv('HTTP_REFERER');
   if (substr_count($url_from,'login.php')<1){
     $_SESSION['URL_FROM'] = $url_from;
    };

   if (isset($_POST['username'],$_POST['password'])){

      $username = $_POST['username'];
      $password = $_POST['password'];

      if (empty($username) || empty($password)){
          $login_erros[] = gettext("Debe ingresar tanto nombre de usuario como contraseña");
      } else {
         if (login_check($username,$password)) {         
            $usuario = obtener_usuario_por_username( $username);
            if (strpos($username,'@') !== false) {
            	 $usuario = obtener_usuario_por_mail( $username);
            } else {
            	$usuario = obtener_usuario_por_username( $username);
            }
            $_SESSION['username'] =  $usuario['username'];
            $_SESSION['usuario_id'] = $usuario['usuario_id'];
           
            $url = get_subdominio_ciudad_id($usuario['ciudad_id']);
            
            exit('<meta http-equiv="refresh" content="0; url=' . urldecode($url) . '"/>');

         } else {         	
              $login_erros[] = gettext("Nombre de usuario o email o contraseña incorrecta");
         }
      }
   }
?>

<div class="container">
<br>
    <div class="center-block logig-form">
        <div class="panel panel-primary">
            <div class="panel-heading"><?php echo gettext("Iniciar Sesión")?></div>
            <div class="panel-body">
            
            <?php
            
            if (!empty($login_erros)){?>
            
             <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <?php echo $login_erros[0]?>
                </div>
            	
            <?php }?>
            
                <form role="form" method="post">
                    <div class="form-group">
                        <div class="input-group login-input">
                            <span class="input-group-addon"><i class="fa fa-user"></i></span>
                            <input type="text" name="username" class="form-control" placeholder="<?php echo gettext("Nombre usuario ó email")?>" required>
                        </div>
                        <br>
                        <div class="input-group login-input">
                            <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                            <input type="password" name="password" class="form-control" placeholder="<?php echo gettext("Contraseña")?>" required>
                        </div>
                        <br>
                        <button type="submit" class="btn btn-ar btn-primary pull-right"><?php echo gettext("Iniciar Sesión")?></button>
                        <br>
                        <br>
                        <hr class="dotted margin-10">
                        <a href="<?php echo get_registro_url_index()?>" class="btn btn-ar btn-success pull-right"><?php echo gettext("Registrate")?></a>
                        <a href="#" id="link_olvide_mi_password" class="btn btn-ar btn-warning"><?php echo gettext("¿Olvidaste tu constraseña?")?></a>
                        <div class="clearfix"></div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
     <div id="div_mail_olvide_password" class="oculto center-block logig-form" style="display: none">
        <p><?php echo gettext("Ingrese su email registrado y se le enviará por correo un link para recuperar su contraseña")?>:</p>
        <p><input type="text" id="mail" name="mail" size="50" maxlength="50"/></p>
        <p><input id="enviar-password-submit" type="submit" value="<?php echo gettext("Enviar")?>" class="btn btn-ar btn-primary"/></p>
     </div>
     
     <section>
     
     <?php //include 'adsense_login_abajo.php';?>
     
     </section>

</div> <!-- container  -->

<?php include 'template_footer_index.php'?>
<?php include 'template_sidebar_index.php';?>

<!-- Scripts -->
<!-- Compiled in vendors.js -->
<!--
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/imagesloaded.pkgd.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bootstrap-switch.min.js"></script>
<script src="assets/js/wow.min.js"></script>
<script src="assets/js/slidebars.min.js"></script>
<script src="assets/js/jquery.bxslider.min.js"></script>
<script src="assets/js/holder.js"></script>
<script src="assets/js/buttons.js"></script>
<script src="assets/js/jquery.mixitup.min.js"></script>
<script src="assets/js/circles.min.js"></script>
<script src="assets/js/masonry.pkgd.min.js"></script>
<script src="assets/js/jquery.matchHeight-min.js"></script>
-->

<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/vendors.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/funcionesjs.js"></script>

<!-- Syntaxhighlighter -->
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shCore.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shBrushXml.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shBrushJScript.js"></script>

<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/app.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/index.js"></script>

</body>

</html>